package jsyf.oa.dao.salary;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import jsyf.oa.entity.salary.SalaryMainEntity;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;

/**
 * Created by Maqiuqiu on 2018/11/17.
 */
@Repository
public class SalaryMainDao extends BaseDao {

    public SalaryMainDao() {
        super.iBaseEntity = new SalaryMainEntity();
    }

    public List<SalaryMainEntity> getEntityListByCondition(String condition, Object[] params) {
        List<JSONObject> jsonList = getJSONListByCondition(condition, params);
        List<SalaryMainEntity> entityList = new ArrayList<>();
        for (int i = 0; i < jsonList.size(); i++) {
            SalaryMainEntity entity = (SalaryMainEntity) convertJson2Entity(jsonList.get(i));
            entityList.add(entity);
        }
        return entityList;
    }

    public List<JSONObject> getListInfo(String condition, int requestPage, int pageSize) {
        StringBuffer sql = new StringBuffer();
        sql.append("select \n" +
                "ID as id,\n" +
                "COMPANY_ID as companyId ,\n" +
                "COMPANY_NAME as companyName,\n" +
                "MONTH as month,\n" +
                "URL as url,\n" +
                "NAME as name,\n" +
                "CREATE_USER_ID as createUserId,\n" +
                "CREATE_TIME as createTime\n" +
                "FROM t_sys_salary\n"+
                "\n" +
                "WHERE\n" +
                "\t1 = 1 "+"\n");
        sql.append(condition);
        sql.append(" GROUP BY MONTH");
        super.appendPageSql(sql, requestPage, pageSize);
        List<JSONObject> records = super.queryForJsonList(sql.toString());
        return records;
    }
    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, SalaryMainEntity.class);
    }
}

